<?php

namespace cms\modules\v1\models\admin;

use cms\modules\v1\models\Common;
use common\models\Functions;
use yii\base\Exception;

/**
 * This is the model class for table "project_info".
 *
 * @property int $id
 * @property string $name
 */
class AdminLoginLog extends Common
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%admin_login_log}}';
    }

    public function getList($page = 1, $size = 50) {
        try {
            $where = [];
//            $count = self::getCountByWhere($where);
            $data = static::setPageinationAPI($page, $size, 0);

            $offset = ($page - 1) * $size;

            $list = static::getByWhere($where, ["*"], 'login_time DESC', $offset, $size);

            $result = [];
            foreach($list as $k => $v) {

                $tmp = [
                    'id' => (int) $v['id'],
                    'loginName' => $v['login_name'],
                    'ip' => $v['login_ip'],
                    'time' => $v['login_time'],
                    'position' => $v['login_position'],
                ];
                $result[] = $tmp;
            }

            $data['data'] = $result;
            return Functions::formatRestAPI(0, '', $data);
        } catch (Exception $e) {
            return Functions::formatRestAPI(1, $e->getMessage());
        }
    }
}
